var listPage = avalon.define({
	$id: "listPage",
	noData:"",
	projects: []
});

mui.ready(function() {
	var uid = $("#uid").val();
	if("" == uid) {
		mui.openWindow({
			url: "dahua://login"
		});
		return false;
	}
	var pageNo = 1;
	var mui_project = mui('#project-list');
	mui.init({
		pullRefresh: {
			container: "#project-list",
			up: {
				auto: true,
				contentdown: $.i18n.prop('contentDown'),
				contentover: $.i18n.prop('contentOver'),
				contentrefresh: $.i18n.prop('contentRefresh'),
				contentnomore: $.i18n.prop('noData'),
				callback: function() {
					listPage.noData="";
					setTimeout(function() {
						mui.ajax('/project/list.json', {
							data: {
								uid: uid,
								pageNo: pageNo
							},
							dataType: 'json',
							success: function(items) {
								var projects = listPage.projects;
								avalon.each(items, function(i, item) {
									projects.push(item);
								});
								listPage.projects = projects;
								mui_project.pullRefresh().endPullupToRefresh(false);
								
								
								if(listPage.projects.length==0){
									listPage.noData="<img src='../../resources/images/noDataImg.png'><p>"+$.i18n.prop('No_data')+"</p>";
								}
							}
						});
						pageNo = pageNo + 1;

					}, window.DAHUA_CONFIG.LOADING_TIME);

				}
			}
		}
	});
	
	
	
	mui(".mui-table-view").on('tap', 'button', function() {
		var pid = this.getAttribute('data-id');
		var url = "edit.html";
		mui.openWindow({
			url: url + "?pid=" + pid
		});
	});

});